﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json.Linq;
using ZBZH_Manage_Order.Models;
using ZBZH_Manage_Order.PublicMethod;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using Model;

namespace ZBZH_Manage_Order.Controllers.MerchantsSettings
{
    public class Order_DishesController : Controller
    {
        //
        // GET: /Order_Dishes/

        ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
        private readonly string DishesPic = ConfigurationManager.AppSettings["Order_Dishes_Photos"];
        private readonly string DishesPics = ConfigurationManager.AppSettings["WeChat_Dishes_Photos"];

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获取系统的增删查改的权限
        /// </summary>
        /// <returns></returns>
        public ActionResult getPower()
        {
            try
            {
                string[] PowerS = null;
                //string RetPower = "";
                Models.ControlPower RetPower = new Models.ControlPower();
                Model.View_OperUser user = (Model.View_OperUser)Session[SessionStorage.OperUser];
                if (user != null)
                {
                    PowerS = user.RolePower.Split(',');//权限码
                    //拼接增删查改的权限
                    foreach (string pow in PowerS)
                    {
                        if (pow == "009004002")
                        {
                            RetPower.Add = 1;
                        }
                        else if (pow == "009004003")
                        {
                            RetPower.Dell = 1;
                        }
                        else if (pow == "009004004")
                        { RetPower.Edit = 1; }
                    }
                }
                else
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面              
                }

                return Json(RetPower);
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取当前操作员拥有商户的权限
        /// </summary>
        /// <returns></returns>
        public ActionResult getMer(JqGridParam jqgridparam)
        {
            try
            {
                Page<Model.Order_Mer_T> page = new Page<Model.Order_Mer_T>();
                List<Model.Order_Mer_T> list = new List<Model.Order_Mer_T>();//定义商品分类设置
                Model.View_OperUser user = (Model.View_OperUser)Session[SessionStorage.OperUser];

                if (user == null)
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面
                }

                string result = service.GetMer(user.OperID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Model.Order_Mer_T m = new Model.Order_Mer_T
                            {
                                MerID = item["MerID"].ToString(),
                                MerName = item["MerName"].ToString(),
                                MerAdr = item["MerAdr"].ToString(),
                                MerCall = item["MerCall"].ToString(),
                                MerTxt = item["MerTxt"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    jqgridparam.records = list.Count;//查询的数据总数
                    var data = new
                    {
                        total = searcho["total"].ToString(),
                        rows = page.FindListPage(list, ref jqgridparam)//返回当前页的数据
                    };
                    return Json(data);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取当前操作员拥有商户的权限
        /// </summary>
        /// <returns></returns>
        public ActionResult getOrderType(string MerID)
        {
            try
            {
                List<Model.Order_DishesType_T> list = new List<Model.Order_DishesType_T>();//定义商品分类设置
                string result = service.GetOrder_DishesType(MerID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Model.Order_DishesType_T m = new Model.Order_DishesType_T();
                            m.DishesTypeID = item["DishesTypeID"].ToString();
                            m.DishesTypeName = item["DishesTypeName"].ToString();
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取商品的一级分类数据
        /// </summary>
        /// <returns></returns>
        public ActionResult getOrderTypes()
        {
            try
            {
                List<Order_DishesType_T> list = new List<Order_DishesType_T>();//定义商品分类设置
                //string result = service.Get_DishesType("", 1);    //获取商品二级分类的数据
                string result = service.Get_Order_DishesType_PC("", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_DishesType_T m = new Order_DishesType_T
                            {
                                DishesTypeID = item["DishesTypeID"].ToString(),
                                DishesTypeName = item["DishesTypeName"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取商品的二级分类数据
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <returns></returns>
        public ActionResult getOrderTypess(string DishesTypeID)
        {
            try
            {
                List<Order_DishesType_T> list = new List<Order_DishesType_T>();//定义商品分类设置
                string result = service.Get_Order_DishesType_PC_T(DishesTypeID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_DishesType_T m = new Order_DishesType_T
                            {
                                DishesTypeID = item["DishesTypeID"].ToString(),
                                DishesTypeName = item["DishesTypeName"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 商品检索时获取二级分类数据
        /// </summary>
        /// <returns></returns>
        public ActionResult getOrderTypesBySearch()
        {
            try
            {
                List<Order_DishesType_T> list = new List<Order_DishesType_T>();//定义商品分类设置
                string result = service.Get_DishesType("", 1);    //获取商品二级分类的数据
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_DishesType_T m = new Order_DishesType_T
                            {
                                DishesTypeID = item["DishesTypeID"].ToString(),
                                DishesTypeName = item["DishesTypeName"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 修改和明细的时候获取一级分类的名称
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <returns></returns>
        public ActionResult getOrderTypesByDishesTypeID(string DishesTypeID)
        {
            try
            {
                List<Order_DishesType_T> list = new List<Order_DishesType_T>();//定义商品分类设置
                string result = service.Get_Order_DishesTypeByDishesTypeID(DishesTypeID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_DishesType_T m = new Order_DishesType_T
                            {
                                DishesTypeID = item["DishesTypeID"].ToString(),
                                DishesTypeName = item["DishesTypeName"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 修改和明细的时候获取二级分类的名称
        /// </summary>
        /// <param name="PantID"></param>
        /// <returns></returns>
        public ActionResult getOrderTypesByPantID(string PantID)
        {
            try
            {
                List<Order_DishesType_T> list = new List<Order_DishesType_T>();//定义商品分类设置
                string result = service.Get_Order_DishesTypeByPantID(PantID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_DishesType_T m = new Order_DishesType_T
                            {
                                DishesTypeID = item["DishesTypeID"].ToString(),
                                DishesTypeName = item["DishesTypeName"].ToString()
                            };
                            list.Add(m);
                        }
                    }
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                return Json(searcho["Msg"].ToString());
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        #region 获取二级分类下的所有商品
        /// <summary>
        /// 商品分类二级删除时先获取二级分类下的所有商品
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <param name="jqgridparam"></param>
        /// <returns></returns>
        public ActionResult getgrid(string DishesTypeID, JqGridParam jqgridparam)
        {
            try
            {
                Page<Order_Dishes_T> page = new Page<Order_Dishes_T>();//分页类定义
                List<Order_Dishes_T> list = new List<Order_Dishes_T>();
                list = GetAllDishes(DishesTypeID);
                if (list != null)
                {
                    jqgridparam.records = list.Count;//查询的数据总数
                    var data = new
                    {
                        total = list.Count.ToString(),
                        rows = page.FindListPage(list, ref jqgridparam)
                    };
                    return Json(data);
                }
                else
                {
                    var data = new
                    {
                        total = "0",
                        rows = list
                    };
                    return Json(data);
                }
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取对应二级分类的所有商品
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <returns></returns>
        public List<Order_Dishes_T> GetAllDishes(string DishesTypeID)
        {
            string result = service.GetOrder_DishesByDY(DishesTypeID, "", 1);
            //string siteUrl = ConfigurationManager.AppSettings["Photo"];
            JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
            string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
            if (bs == "1")//返回结果正常
            {
                List<Order_Dishes_T> list = new List<Order_Dishes_T>();//用于保存当前商户下的所有菜品集合
                IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                if (jieguo.Count > 0)
                {
                    foreach (JToken item in jieguo)
                    {
                        // List<Model.Sys_Component_T> list_com = new List<Model.Sys_Component_T>();
                        List<Order_Dishes_T> list_Dishes = new List<Order_Dishes_T>();
                        Order_Dishes_T m = new Order_Dishes_T
                        {
                            DishesID = item["DishesID"].ToString(),
                            DishesNmae = item["DishesNmae"].ToString(),
                            DishesTypeID = item["DishesTypeID"].ToString(),
                            DishesEnableInt = int.Parse(item["DishesEnableInt"].ToString()),
                            DishesIsInt = int.Parse(item["DishesIsInt"].ToString()),
                            DishesMon = DataHelper.MoneyToYuang(item["DishesMon"].ToString()),
                            DelPackMon = DataHelper.MoneyToYuang(item["DelPackMon"].ToString()),
                            DishesPay = DataHelper.MoneyToYuang(item["DishesPay"].ToString()),
                            DishesVol = int.Parse(item["DishesVol"].ToString()),
                            DishesTxt = item["DishesTxt"].ToString(),
                            DishesSummary = item["DishesSummary"].ToString(),
                            DishesParam = item["DishesParam"].ToString(),
                            //m.DishesPic =siteUrl+ item["DishesPic"].ToString();
                            DishesPic = item["DishesPic"].ToString(),
                            DishesPicBig = item["DishesPicBig"].ToString(),
                            DishesPicSmall = item["DishesPicSmall"].ToString(),
                            DishesEvaNun = int.Parse(item["DishesEvaNun"].ToString()),
                            DishesEvaTxt = int.Parse(item["DishesEvaTxt"].ToString()),
                            DishesEvaX = int.Parse(item["DishesEvaX"].ToString()),
                            DishesGood = int.Parse(item["DishesGood"].ToString()),
                            DishesTypeState = int.Parse(item["DishesTypeState"].ToString()),
                            IntBZ = item["IntBZ"].ToString(),
                            DishesTypeName = item["DishesTypeName"].ToString(),
                            BarCode = item["BarCode"].ToString()
                        };
                        list.Add(m);
                    }
                }
                //Session[SessionStorage.DisheList] = list;//将实体类保存至Session
                return list;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取全部商品
        /// </summary>
        /// <param name="jqgridparam"></param>
        /// <returns></returns>
        public ActionResult getgrids(JqGridParam jqgridparam)
        {
            try
            {
                Page<Order_Dishes_T> page = new Page<Order_Dishes_T>();//分页类定义
                List<Order_Dishes_T> list = new List<Order_Dishes_T>();
                list = GetAllDishess();
                if (list != null)
                {
                    jqgridparam.records = list.Count;//查询的数据总数
                    var data = new
                    {
                        total = list.Count.ToString(),
                        rows = page.FindListPage(list, ref jqgridparam)
                    };
                    return Json(data);
                }
                else
                {
                    var data = new
                    {
                        total = "0",
                        rows = list
                    };
                    return Json(data);
                }
            }
            catch (Exception ex)
            {
                return Json("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 全部商品数据
        /// </summary>
        /// <returns></returns>
        public List<Order_Dishes_T> GetAllDishess()
        {
            string result = service.Get_Order_Dishes("", 1);
            //string siteUrl = ConfigurationManager.AppSettings["Photo"];
            JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
            string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
            if (bs == "1")//返回结果正常
            {
                List<Order_Dishes_T> list = new List<Order_Dishes_T>();//用于保存当前商户下的所有菜品集合
                IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                if (jieguo.Count > 0)
                {
                    foreach (JToken item in jieguo)
                    {
                        #region 获取一级分类的名称
                        var DishesTypeID2 = item["DishesTypeID"].ToString();
                        var DishesTypeID_One = "";
                        var DishesTypeName_One = "";
                        if (DishesTypeID2 != null)
                        {
                            string result2 = service.Get_Order_DishesTypeByDishesTypeID(DishesTypeID2, "", 1);
                            JObject searcho2 = JObject.Parse(result2);//将服务返回的结果进行优化
                            string bs2 = searcho2["BS"].ToString();//获取返回结果是否正常标识
                            string rows = searcho2["rows"].ToString();//获取返回数据结果
                            if (bs2 == "1" && rows != null)//返回结果正常
                            {
                                IList<JToken> jieguo2 = searcho2["rows"].Children().ToList();//解析返回的结果
                                if (jieguo2.Count > 0)
                                {
                                    foreach (JToken item2 in jieguo2)
                                    {
                                        DishesTypeID_One = item2["DishesTypeID"].ToString();
                                        DishesTypeName_One = item2["DishesTypeName"].ToString();
                                    }
                                }
                            }
                        }
                        #endregion

                        Order_Dishes_T m = new Order_Dishes_T
                        {
                            DishesID = item["DishesID"].ToString(),
                            DishesNmae = item["DishesNmae"].ToString(),
                            DishesTypeID = item["DishesTypeID"].ToString(),
                            DishesEnableInt = int.Parse(item["DishesEnableInt"].ToString()),
                            DishesIsInt = int.Parse(item["DishesIsInt"].ToString()),
                            //m.DishesMon = DataHelper.MoneyToYuang(item["DishesMon"].ToString());
                            //m.DelPackMon = DataHelper.MoneyToYuang(item["DelPackMon"].ToString());
                            //m.DishesPay = DataHelper.MoneyToYuang(item["DishesPay"].ToString());
                            DishesMon = item["DishesMon"].ToString(),
                            DelPackMon = item["DelPackMon"].ToString(),
                            DishesPay = item["DishesPay"].ToString(),
                            DishesVol = int.Parse(item["DishesVol"].ToString()),
                            DishesTxt = item["DishesTxt"].ToString(),
                            DishesSummary = item["DishesSummary"].ToString(),
                            DishesParam = item["DishesParam"].ToString(),
                            //m.DishesPic =siteUrl+ item["DishesPic"].ToString();
                            DishesPic = item["DishesPic"].ToString(),
                            DishesPicBig = item["DishesPicBig"].ToString(),
                            DishesPicSmall = item["DishesPicSmall"].ToString(),
                            DishesEvaNun = int.Parse(item["DishesEvaNun"].ToString()),
                            DishesEvaTxt = int.Parse(item["DishesEvaTxt"].ToString()),
                            DishesEvaX = int.Parse(item["DishesEvaX"].ToString()),
                            DishesGood = int.Parse(item["DishesGood"].ToString()),
                            DishesTypeState = int.Parse(item["DishesTypeState"].ToString()),
                            IntBZ = item["IntBZ"].ToString(),
                            DishesTypeName = item["DishesTypeName"].ToString(),
                            DishesTypeID_One = DishesTypeID_One,
                            DishesTypeName_One = DishesTypeName_One,
                            BarCode = item["BarCode"].ToString()
                        };
                        list.Add(m);
                    }
                }
                Session[SessionStorage.DisheList] = list;//将实体类保存至Session
                return list;
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region 原上传照片本地保存
        /// <summary>
        /// 原上传照片本地保存
        /// </summary>
        /// <param name="fileToUpload"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ToLead(HttpPostedFileBase[] fileToUpload, string id)
        {
            try
            {
                //Model.View_User userinfoModel = (Model.View_User)Session[SessionStorage.UserLogin];//将Session保存的实体转成可直接使用的实体
                //int acc = userinfoModel.AccID;
                string FileUrl = string.Empty;
                //string daPic = Server.MapPath("~/Dishes");
                string DishesPic = ConfigurationManager.AppSettings["Order_Dishes_Photos"] + "\\Iamges\\" + id;
                string DishesPics = ConfigurationManager.AppSettings["WeChat_Dishes_Photos"] + "\\Iamges\\" + id;
                string[] stringArray = new string[] { DishesPic, DishesPics };
                foreach (var item in stringArray)
                {
                    if (!Directory.Exists(item))//判断目录是否存在
                    {
                        Directory.CreateDirectory(item);
                    }
                    foreach (HttpPostedFileBase file in fileToUpload)
                    {
                        //string siteUrl = ConfigurationManager.AppSettings["Photo"] + "/Dishes/";
                        //string path = Path.Combine(Server.MapPath(siteUrl), Path.GetFileName(file.FileName));//将照片存入指定路径文件

                        string path = Path.Combine(item, Path.GetFileName(file.FileName));//将照片存入本地文件
                        //string path = Path.Combine(Server.MapPath("~/FileUpLoad/Photo"), Path.GetFileName(file.FileName));//将照片存入本地文件
                        file.SaveAs(path);
                        FileUrl = path;
                        FileStream Pic = new FileStream(path, FileMode.Open);
                        byte[] PicByte = new byte[Pic.Length];
                        Pic.Read(PicByte, 0, (int)Pic.Length);
                        Pic.Dispose();
                        Pic.Close();
                        fileToUpload.Clone();
                        //string a = "/Dishes/" + Path.GetFileName(file.FileName);
                        //string result = service.SetDishPhoto(acc, PicByte, 1, GetYZM._YZM, 1);
                    }
                }

                return Content("ok");
            }
            catch (Exception ex)
            {
                Log.Debug("上传照片ToLead：", ex.Message);
                return Content("上传失败");
            }
        }
        #endregion

        #region 裁剪图片上传本地保存
        /// <summary>
        /// 裁剪图片上传本地保存
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="pw"></param>
        /// <param name="ph"></param>
        /// <param name="t"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult SaveImg(int x, int y, int w, int h, int pw, int ph, string t, string id)
        {
            try
            {
                //string du= Session["startDate"].ToString();
                string DishesPic = ConfigurationManager.AppSettings["Order_Dishes_Photos"] + "\\Iamges\\" + id;
                string DishesPics = ConfigurationManager.AppSettings["WeChat_Dishes_Photos"] + "\\Iamges\\" + id;
                string[] stringArray = new string[] { DishesPic, DishesPics };
                foreach (var item in stringArray)
                {
                    string path = Path.Combine(item, Path.GetFileName(t));
                    var DishesPicName = Path.GetExtension(t);
                    string daPic = Path.Combine(item, Path.GetFileName(id + "da" + DishesPicName));
                    string xiaoPic = Path.Combine(item, Path.GetFileName(id + "xiao" + DishesPicName));

                    Bitmap source = new Bitmap(path);
                    Bitmap resizeBitmap = new Bitmap(pw, ph);
                    Graphics g = Graphics.FromImage(resizeBitmap);
                    // 插值算法的质量
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.DrawImage(source, new Rectangle(0, 0, pw, ph), new Rectangle(0, 0, source.Width, source.Height), GraphicsUnit.Pixel);
                    g.Dispose();
                    Bitmap newImg = new Bitmap(w, h, PixelFormat.Format24bppRgb);
                    g = Graphics.FromImage(newImg);
                    g.DrawImage(resizeBitmap, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
                    g.Dispose();
                    Bitmap bm2 = new Bitmap(newImg, 400, 400);
                    bm2.Save(daPic);
                    Bitmap bm1 = new Bitmap(newImg, 94, 94);
                    bm1.Save(xiaoPic);
                    newImg.Dispose();
                    source.Dispose();
                    resizeBitmap.Dispose();
                    bm2.Dispose();
                    bm1.Dispose();                    
                }
                return Content("1");
            }
            catch (Exception ex)
            {
                Log.Debug("裁剪图片SaveImg：", ex.Message);
                return Content("裁剪图片失败");
            }

        }
        #endregion

        #region 图片转byte
        /// <summary>
        /// 图片转byte
        /// </summary>
        /// <param name="imagepath"></param>
        /// <returns></returns>
        public byte[] GetPictureData(string imagepath)
        {
            /**/////根据图片文件的路径使用文件流打开，并保存为byte[] 
            Log.Debug("图片转byte", "进入");
            using (FileStream fs = new FileStream(imagepath, FileMode.Open))
            {
                byte[] byData = new byte[fs.Length];
                fs.Read(byData, 0, byData.Length);
                fs.Dispose();
                fs.Close();
                return byData;
            };//可以是其他重载方法 

        }
        #endregion

        #region 保存上传图片路径
        /// <summary>
        /// 保存上传图片路径
        /// </summary>
        /// <param name="DisheID"></param>
        /// <param name="PicName"></param>
        /// <returns></returns>
        public ActionResult ToLoadPic(string DisheID, string PicName)
        {
            try
            {
                string DishesPic = ConfigurationManager.AppSettings["Order_Dishes_Photos"] + "\\Iamges\\" + DisheID;
                var DishesPicName = Path.GetExtension(PicName);
                string Pic = Path.Combine(DishesPic, Path.GetFileName(PicName));
                string daPic = Path.Combine(DishesPic, Path.GetFileName(DisheID + "da" + DishesPicName));
                string xiaoPic = Path.Combine(DishesPic, Path.GetFileName(DisheID + "xiao" + DishesPicName));

                //Log.Debug("ToLoadPic 图片了路径：", Pic + "和" + daPic + "和" + xiaoPic);
                //byte[] yPic = GetPictureData(Pic);
                //Log.Debug("ToLoadPic 图片转换byt：", "1");
                //byte[] dPic = GetPictureData(daPic);
                //Log.Debug("ToLoadPic 图片转换byt：", "1");
                //byte[] xPic = GetPictureData(xiaoPic);
                //Log.Debug("ToLoadPic 图片转换byt：", "1");
                //string url = "/Dishes/" + PicName;
                //string result = service.SetDishPhoto(DisheID, url, GetYZM._YZM, 1);
                string DishesURL = "/Dishes/Iamges/" + DisheID + Pic.Replace(DishesPic, "").Replace('\\', '/'); //原图片保存路径
                string DishesDaURL = "/Dishes/Iamges/" + DisheID + daPic.Replace(DishesPic, "").Replace('\\', '/'); //大图片保存路径
                string DishesXiaoURL = "/Dishes/Iamges/" + DisheID + xiaoPic.Replace(DishesPic, "").Replace('\\', '/'); //小图片保存路径

                //string results = service.UpdatePhoto(DisheID, dPic, xPic, GetYZM._YZM, 1);
                string results = service.UpdateDishesPhoto(DisheID, DishesURL, DishesDaURL, DishesXiaoURL, GetYZM._YZM, 1);
                //Log.Debug("ToLoadPic 接口返回", results);
                JObject searcho = JObject.Parse(results);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                //Log.Debug("ToLoadPic：", bs);
                if (bs == "1")
                {
                    //List<View_Order_Dishes> list = (List<View_Order_Dishes>)Session[SessionStorage.DisheList];
                    //foreach (View_Order_Dishes item in list)
                    //{
                    //    if (item.DishesID == DisheID)
                    //    {
                    //        //item.DishesPic = url;
                    //    }
                    //}
                    //Session[SessionStorage.DisheList] = null;
                    //Session[SessionStorage.DisheList] = list;
                    //byte[] up = service.GetPhoto(DisheID, 1 ,GetYZM._YZM, 1);
                    //Bitmap tp=BytesToBitmap(up);
                    //string bd = Path.Combine(Server.MapPath("~/Dishes"), Path.GetFileName("11.jpg"));
                    //tp.Save(bd);
                    return Content(bs);
                }
                else { return Content("上传失败"); }
            }
            catch (Exception es)
            {
                Log.Debug("单独上传照片ToLoadPic：", es.Message);
                return Content("上传失败");
            }
        }
        #endregion

        #region byte转Bitmap
        /// <summary>
        /// byte转Bitmap
        /// </summary>
        /// <param name="Bytes"></param>
        /// <returns></returns>
        public static Bitmap BytesToBitmap(byte[] Bytes)
        {
            MemoryStream stream = null;
            try
            {
                stream = new MemoryStream(Bytes);
                return new Bitmap((Image)new Bitmap(stream));
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            finally
            {
                stream.Close();
            }
        }
        #endregion

        #region 根据id获取图片
        /// <summary>
        /// #endregion
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Image(string id)
        {
            try
            {
                //FileResult
                byte[] up = service.GetPhoto(id, 1, GetYZM._YZM, 1);
                Bitmap tp = BytesToBitmap(up);
                string bd = Path.Combine(Server.MapPath("~/Dishes"), Path.GetFileName(id + "bd.jpg"));
                tp.Save(bd);

                //byte[] image = service.GetPhoto(id, 1, GetYZM._YZM, 1);
                //return new FileContentResult(image, "image/jpeg");
                return Content(bd);
            }
            catch (Exception es)
            {
                Log.Debug("根据id获取图片Image：", es.Message);
                return Content("获取图片失败");

            }
        }
        #endregion

        #region 增删改商品信息
        /// <summary>
        /// 增、删、改商品信息
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateOrder_Dishes(int Tag, Order_Dishes_T Order_Dishes)
        {
            try
            {
                string result = "";
                View_OperUser user = (View_OperUser)Session[SessionStorage.OperUser];
                if (user == null)
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面
                }

                #region 删除本地图片和文件夹
                if (Tag == 3 && Order_Dishes.DishesID != null)
                {
                    #region 商品轮播图片删除
                    List<Order_Carousel_T> list = new List<Order_Carousel_T>();
                    string result2 = service.GetOrder_DishesCarousel_Photo(Order_Dishes.DishesID, "", 1);
                    JObject searcho2 = JObject.Parse(result2);//将服务返回的结果进行优化
                    string bs2 = searcho2["BS"].ToString();//获取返回结果是否正常标识
                    if (bs2 == "1")//返回结果正常
                    {
                        IList<JToken> jieguo = searcho2["rows"].Children().ToList();//解析返回的结果
                        if (jieguo.Count > 0)
                        {
                            foreach (JToken item in jieguo)
                            {
                                Order_Carousel_T m = new Order_Carousel_T
                                {
                                    CarouselID = item["CarouselID"].ToString(),
                                    CarouselURL = item["CarouselURL"].ToString(),
                                    DishesID = item["DishesID"].ToString(),
                                    CarouselName = item["CarouselName"].ToString(),
                                    CreateTime = item["CreateTime"].ToString(),
                                };
                                list.Add(m);
                            }
                        }
                        if (list != null && list.Count() > 0)
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                string result3 = service.DishesCarousel_Photo_Del(user.OperID, list[i].CarouselID, 1);
                                JObject searcho3 = JObject.Parse(result3);//将服务返回的结果进行优化
                                string bs3 = searcho3["BS"].ToString();
                                if (bs3 == "1")
                                {
                                    //删除本地保存的图片文件夹                                   
                                    string[] stringArray = new string[] { DishesPic, DishesPics };
                                    foreach (var item in stringArray)
                                    {
                                        DirectoryInfo file = new DirectoryInfo((item + "/Carousel/" + Order_Dishes.DishesID).Replace('\\', '/'));
                                        if (file.Exists)
                                        {
                                            DirectoryInfo[] childs = file.GetDirectories();
                                            foreach (DirectoryInfo child in childs)
                                            {
                                                child.Delete(true);
                                            }
                                            file.Delete(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 商品概述和参数图片删除
                    List<Order_ParameterOverview_T> list2 = new List<Order_ParameterOverview_T>();
                    string result4 = service.GetOrder_DishesParameterOverview_Photo(Order_Dishes.DishesID, "", 1);
                    JObject searcho4 = JObject.Parse(result4);//将服务返回的结果进行优化
                    string bs4 = searcho4["BS"].ToString();//获取返回结果是否正常标识
                    if (bs4 == "1")//返回结果正常
                    {
                        IList<JToken> jieguo = searcho4["rows"].Children().ToList();//解析返回的结果
                        if (jieguo.Count > 0)
                        {
                            foreach (JToken item in jieguo)
                            {
                                Order_ParameterOverview_T m = new Order_ParameterOverview_T
                                {
                                    ParameterOverviewID = item["ParameterOverviewID"].ToString(),
                                    ParameterOverviewURL = item["ParameterOverviewURL"].ToString(),
                                    DishesID = item["DishesID"].ToString(),
                                    ParameterOverviewName = item["ParameterOverviewName"].ToString(),
                                    CreateTime = item["CreateTime"].ToString(),
                                };
                                list2.Add(m);
                            }
                        }
                        if (list2 != null && list2.Count() > 0)
                        {
                            for (int i = 0; i < list2.Count; i++)
                            {
                                string result5 = service.DishesParameterOverview_Photo_Del(user.OperID, list2[i].ParameterOverviewID, 1);
                                JObject searcho5 = JObject.Parse(result5);//将服务返回的结果进行优化
                                string bs5 = searcho5["BS"].ToString();
                                if (bs5 == "1")
                                {
                                    //删除本地保存的图片文件夹                                   
                                    string[] stringArray = new string[] { DishesPic, DishesPics };
                                    foreach (var item in stringArray)
                                    {
                                        DirectoryInfo file = new DirectoryInfo((item + "/ParameterOverview/" + Order_Dishes.DishesID).Replace('\\', '/'));
                                        if (file.Exists)
                                        {
                                            DirectoryInfo[] childs = file.GetDirectories();
                                            foreach (DirectoryInfo child in childs)
                                            {
                                                child.Delete(true);
                                            }
                                            file.Delete(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region 商品图片删除
                    string[] stringPicArray = new string[] { DishesPic, DishesPics };
                    foreach (var item in stringPicArray)
                    {
                        DirectoryInfo file = new DirectoryInfo((item + "/Iamges/" + Order_Dishes.DishesID).Replace('\\', '/'));
                        if (file.Exists)
                        {
                            DirectoryInfo[] childs = file.GetDirectories();
                            foreach (DirectoryInfo child in childs)
                            {
                                child.Delete(true);
                            }
                            file.Delete(true);
                        }
                    }
                    #endregion
                }
                #endregion

                #region 转换传入的商品信息
                Model.Order_Dishes_T New_Dishes = new Model.Order_Dishes_T
                {
                    DishesID = Order_Dishes.DishesID,
                    DishesNmae = Order_Dishes.DishesNmae,
                    DishesTypeID = Order_Dishes.DishesTypeID,
                    DishesEnableInt = Order_Dishes.DishesEnableInt,
                    DishesIsInt = Order_Dishes.DishesIsInt,
                    //New_Dishes.DishesMon = int.Parse((double.Parse(Order_Dishes.DishesMon) * 100).ToString());
                    //New_Dishes.DelPackMon = int.Parse((double.Parse(Order_Dishes.DelPackMon) * 100).ToString());
                    //New_Dishes.DishesPay = int.Parse((double.Parse(Order_Dishes.DishesPay) * 100).ToString());
                    DishesMon = float.Parse((double.Parse(Order_Dishes.DishesMon) * 1).ToString()),
                    DelPackMon = float.Parse((double.Parse(Order_Dishes.DelPackMon) * 1).ToString()),
                    DishesPay = float.Parse((double.Parse(Order_Dishes.DishesPay) * 1).ToString()),
                    DishesVol = Order_Dishes.DishesVol,
                    DishesTxt = Order_Dishes.DishesTxt,
                    DishesSummary = Order_Dishes.DishesSummary.Replace('≮', '<').Replace('≯', '>'),
                    DishesParam = Order_Dishes.DishesParam.Replace('≮', '<').Replace('≯', '>'),
                    DishesPic = Order_Dishes.DishesPic,
                    DishesPicBig = Order_Dishes.DishesPicBig,
                    DishesPicSmall = Order_Dishes.DishesPicSmall,
                    DishesEvaNun = Order_Dishes.DishesEvaNun,
                    DishesEvaTxt = Order_Dishes.DishesEvaTxt,
                    DishesEvaX = Order_Dishes.DishesEvaX,
                    DishesGood = Order_Dishes.DishesGood,
                    IntBZ = Order_Dishes.IntBZ,
                    BarCode = Order_Dishes.BarCode
                };
                #endregion

                string a = New_Dishes.ToJson();
                result = service.SetOrder_Dishes(user.OperID, New_Dishes.ToJson(), Tag, GetYZM._YZM, 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    return Content(bs);
                }
                else
                {
                    return Content(searcho["Msg"].ToString());
                }
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex.Message + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 商品批量删除
        /// </summary>
        /// <param name="DishesID"></param>
        /// <returns></returns>
        public ActionResult UpdateOrder_Dishes_Del(string DishesID)
        {
            try
            {
                string result = "";
                View_OperUser user = (View_OperUser)Session[SessionStorage.OperUser];
                if (user == null)
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面
                }

                DishesID = DishesID.Remove(0, 1);

                #region 删除本地图片和文件夹
                string[] DishesIDInfo = DishesID.Split(',');
                if (DishesIDInfo.Count() > 0)
                {
                    foreach (var DishesIDIitem in DishesIDInfo)
                    {                        
                        if (DishesIDIitem != null && DishesIDIitem.Count() > 0)
                        {
                            #region 商品轮播图片删除
                            List<Order_Carousel_T> list = new List<Order_Carousel_T>();
                            string result2 = service.GetOrder_DishesCarousel_Photo(DishesIDIitem, "", 1);
                            JObject searcho2 = JObject.Parse(result2);//将服务返回的结果进行优化
                            string bs2 = searcho2["BS"].ToString();//获取返回结果是否正常标识
                            if (bs2 == "1")//返回结果正常
                            {
                                IList<JToken> jieguo = searcho2["rows"].Children().ToList();//解析返回的结果
                                if (jieguo.Count > 0)
                                {
                                    foreach (JToken item in jieguo)
                                    {
                                        Order_Carousel_T m = new Order_Carousel_T
                                        {
                                            CarouselID = item["CarouselID"].ToString(),
                                            CarouselURL = item["CarouselURL"].ToString(),
                                            DishesID = item["DishesID"].ToString(),
                                            CarouselName = item["CarouselName"].ToString(),
                                            CreateTime = item["CreateTime"].ToString(),
                                        };
                                        list.Add(m);
                                    }
                                }
                                if (list != null && list.Count() > 0)
                                {
                                    for (int i = 0; i < list.Count; i++)
                                    {
                                        string result3 = service.DishesCarousel_Photo_Del(user.OperID, list[i].CarouselID, 1);
                                        JObject searcho3 = JObject.Parse(result3);//将服务返回的结果进行优化
                                        string bs3 = searcho3["BS"].ToString();
                                        if (bs3 == "1")
                                        {
                                            //删除本地保存的图片文件夹                                   
                                            string[] stringArray = new string[] { DishesPic, DishesPics };
                                            foreach (var item in stringArray)
                                            {
                                                DirectoryInfo file = new DirectoryInfo((item + "/Carousel/" + DishesIDIitem).Replace('\\', '/'));
                                                if (file.Exists)
                                                {
                                                    DirectoryInfo[] childs = file.GetDirectories();
                                                    foreach (DirectoryInfo child in childs)
                                                    {
                                                        child.Delete(true);
                                                    }
                                                    file.Delete(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 商品概述和参数图片删除
                            List<Order_ParameterOverview_T> list2 = new List<Order_ParameterOverview_T>();
                            string result4 = service.GetOrder_DishesParameterOverview_Photo(DishesIDIitem, "", 1);
                            JObject searcho4 = JObject.Parse(result4);//将服务返回的结果进行优化
                            string bs4 = searcho4["BS"].ToString();//获取返回结果是否正常标识
                            if (bs4 == "1")//返回结果正常
                            {
                                IList<JToken> jieguo = searcho4["rows"].Children().ToList();//解析返回的结果
                                if (jieguo.Count > 0)
                                {
                                    foreach (JToken item in jieguo)
                                    {
                                        Order_ParameterOverview_T m = new Order_ParameterOverview_T
                                        {
                                            ParameterOverviewID = item["ParameterOverviewID"].ToString(),
                                            ParameterOverviewURL = item["ParameterOverviewURL"].ToString(),
                                            DishesID = item["DishesID"].ToString(),
                                            ParameterOverviewName = item["ParameterOverviewName"].ToString(),
                                            CreateTime = item["CreateTime"].ToString(),
                                        };
                                        list2.Add(m);
                                    }
                                }
                                if (list2 != null && list2.Count() > 0)
                                {
                                    for (int i = 0; i < list2.Count; i++)
                                    {
                                        string result5 = service.DishesParameterOverview_Photo_Del(user.OperID, list2[i].ParameterOverviewID, 1);
                                        JObject searcho5 = JObject.Parse(result5);//将服务返回的结果进行优化
                                        string bs5 = searcho5["BS"].ToString();
                                        if (bs5 == "1")
                                        {
                                            //删除本地保存的图片文件夹                                   
                                            string[] stringArray = new string[] { DishesPic, DishesPics };
                                            foreach (var item in stringArray)
                                            {
                                                DirectoryInfo file = new DirectoryInfo((item + "/ParameterOverview/" + DishesIDIitem).Replace('\\', '/'));
                                                if (file.Exists)
                                                {
                                                    DirectoryInfo[] childs = file.GetDirectories();
                                                    foreach (DirectoryInfo child in childs)
                                                    {
                                                        child.Delete(true);
                                                    }
                                                    file.Delete(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 商品图片删除
                            string[] stringPicArray = new string[] { DishesPic, DishesPics };
                            foreach (var item in stringPicArray)
                            {
                                DirectoryInfo file = new DirectoryInfo((item + "/Iamges/" + DishesIDIitem).Replace('\\', '/'));
                                if (file.Exists)
                                {
                                    DirectoryInfo[] childs = file.GetDirectories();
                                    foreach (DirectoryInfo child in childs)
                                    {
                                        child.Delete(true);
                                    }
                                    file.Delete(true);
                                }
                            }
                            #endregion
                        }                       
                    }
                }
                #endregion

                result = service.UpdateOrder_Dishes_Del(user.OperID, DishesID, 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    return Content(bs);
                }
                else
                {
                    return Content(searcho["Msg"].ToString());
                }
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex.Message + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 商品批量上架
        /// </summary>
        /// <param name="DishesID"></param>
        /// <returns></returns>
        public ActionResult UpdateOrder_Dishes_Up(string DishesID)
        {
            try
            {
                string result = "";
                View_OperUser user = (View_OperUser)Session[SessionStorage.OperUser];
                if (user == null)
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面
                }

                DishesID = DishesID.Remove(0, 1);
                result = service.UpdateOrder_Dishes_Up(user.OperID, DishesID, 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    return Content(bs);
                }
                else
                {
                    return Content(searcho["Msg"].ToString());
                }
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 商品批量下架
        /// </summary>
        /// <param name="DishesID"></param>
        /// <returns></returns>
        public ActionResult UpdateOrder_Dishes_Down(string DishesID)
        {
            try
            {
                string result = "";
                View_OperUser user = (View_OperUser)Session[SessionStorage.OperUser];
                if (user == null)
                {
                    return RedirectToAction("LoginPage", "Login");  //czx:修改为登录者的Session异常时，直接跳转到登录页面
                }

                DishesID = DishesID.Remove(0, 1);
                result = service.UpdateOrder_Dishes_Down(user.OperID, DishesID, 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    return Content(bs);
                }
                else
                {
                    return Content(searcho["Msg"].ToString());
                }
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex + "请联系管理员解决");
            }
        }
        #endregion

        #region 查询商品
        /// <summary>
        /// 查询商品
        /// </summary>
        /// <param name="DishesName">商品名称</param>
        /// <param name="DishesType">商品一级分类</param>
        /// <param name="DishesType2">商品二级分类</param>
        /// <param name="jqgridparam"></param>
        /// <returns></returns>
        public ActionResult searchDishes(string DishesType, string DishesType2, string DishesName, JqGridParam jqgridparam)
        {
            try
            {
                Page<Order_Dishes_T> page = new Page<Order_Dishes_T>();//分页类定义
                List<Order_Dishes_T> newuc = new List<Order_Dishes_T>();//定义一个新的对象，用于保存查询后的实体类列表
                List<Order_Dishes_T> ls = GetAllDishess();//查询该商户的所有商品
                for (int i = 0; i < ls.Count; i++)
                {
                    if (DishesName != "" && DishesType != "" && DishesType2 != "")
                    {
                        if (ls[i].DishesNmae.IndexOf(DishesName) > -1 && ls[i].DishesTypeID_One == DishesType && ls[i].DishesTypeID == DishesType2)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName != "" && DishesType != "" && DishesType2 == "")
                    {
                        if (ls[i].DishesNmae.IndexOf(DishesName) > -1 && ls[i].DishesTypeID_One == DishesType)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName != "" && DishesType == "" && DishesType2 != "")
                    {
                        if (ls[i].DishesNmae.IndexOf(DishesName) > -1 && ls[i].DishesTypeID == DishesType2)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName == "" && DishesType != "" && DishesType2 != "")
                    {
                        if (ls[i].DishesTypeID_One == DishesType && ls[i].DishesTypeID == DishesType2)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName != "" && DishesType == "" && DishesType2 == "")
                    {
                        if (ls[i].DishesNmae.IndexOf(DishesName) > -1)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName == "" && DishesType != "" && DishesType2 == "")
                    {
                        if (ls[i].DishesTypeID_One == DishesType)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName == "" && DishesType == "" && DishesType2 != "")
                    {
                        if (ls[i].DishesTypeID == DishesType2)
                        {
                            newuc.Add(ls[i]);
                        }
                    }
                    else if (DishesName == "" && DishesType == "" && DishesType2 == "")
                    {
                        newuc.Add(ls[i]);
                    }
                }
                jqgridparam.records = newuc.Count;
                var data = new
                {
                    total = newuc.Count,
                    rows = page.FindListPage(newuc, ref jqgridparam)
                };
                return Json(data);
            }
            catch (Exception) { return null; }
        }
        #endregion

        #region 商品定义 用于金额转换
        /// <summary>
        /// 商品信息定义（用于金额转换）
        /// </summary>
        public class Order_Dishes_T
        {
            public int DishesEnableInt { get; set; }
            public int DishesEvaNun { get; set; }
            public int DishesEvaTxt { get; set; }
            public int DishesEvaX { get; set; }
            public int DishesGood { get; set; }
            public string DishesID { get; set; }
            public int DishesIsInt { get; set; }
            public string DishesMon { get; set; }
            public string DishesNmae { get; set; }
            public string DishesPay { get; set; }
            public string DishesPic { get; set; }
            public string DishesPicBig { get; set; }
            public string DishesPicSmall { get; set; }
            public string DishesTxt { get; set; }
            public string DishesSummary { get; set; }
            public string DishesParam { get; set; }
            public string DishesTypeID { get; set; }
            public string DishesTypeName { get; set; }
            public string DishesTypeID_One { get; set; }
            public string DishesTypeName_One { get; set; }
            public int DishesTypeState { get; set; }
            public int DishesVol { get; set; }
            public string IntBZ { get; set; }
            public string DelPackMon { get; set; }
            public string BarCode { get; set; }
        }
        #endregion

        #region 根据DishesID获取商品图片信息
        /// <summary>
        /// 获取商品照片
        /// </summary>
        /// <param name="DisheID">商品ID</param>
        /// <returns></returns>
        public ActionResult getDishePhoto(string DisheID)
        {
            try
            {
                string pic = "";
                List<Order_Dishes_T> list = (List<Order_Dishes_T>)Session[SessionStorage.DisheList];
                foreach (Order_Dishes_T item in list)
                {
                    if (DisheID == item.DishesID)
                    {
                        pic = item.DishesPicSmall;
                    }
                }
                return Content(pic);
            }
            catch (Exception) { return null; }
        }

        /// <summary>
        /// 获取轮播图图片
        /// </summary>
        /// <param name="DishesID"></param>
        /// <returns></returns>
        public ActionResult GetOrder_DishesCarousel_Photo(string DishesID)
        {
            try
            {
                List<Order_Carousel_T> list = new List<Order_Carousel_T>();
                string result = service.GetOrder_DishesCarousel_Photo(DishesID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_Carousel_T m = new Order_Carousel_T
                            {
                                CarouselID = item["CarouselID"].ToString(),
                                CarouselURL = item["CarouselURL"].ToString(),
                                DishesID = item["DishesID"].ToString(),
                                CarouselName = item["CarouselName"].ToString(),
                                CreateTime = item["CreateTime"].ToString(),
                            };
                            list.Add(m);
                        }
                    }
                    if (list != null && list.Count() > 0)
                    {
                        return Json(list);
                    }
                }

                return Content("0");
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex.Message + "请联系管理员解决");
            }
        }

        /// <summary>
        /// 获取概述和参数图片
        /// </summary>
        /// <param name="DishesID"></param>
        /// <returns></returns>
        public ActionResult GetOrder_DishesParameterOverview_Photo(string DishesID)
        {
            try
            {
                List<Order_ParameterOverview_T> list = new List<Order_ParameterOverview_T>();
                string result = service.GetOrder_DishesParameterOverview_Photo(DishesID, "", 1);
                JObject searcho = JObject.Parse(result);//将服务返回的结果进行优化
                string bs = searcho["BS"].ToString();//获取返回结果是否正常标识
                if (bs == "1")//返回结果正常
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();//解析返回的结果
                    if (jieguo.Count > 0)
                    {
                        foreach (JToken item in jieguo)
                        {
                            Order_ParameterOverview_T m = new Order_ParameterOverview_T
                            {
                                ParameterOverviewID = item["ParameterOverviewID"].ToString(),
                                ParameterOverviewURL = item["ParameterOverviewURL"].ToString(),
                                DishesID = item["DishesID"].ToString(),
                                ParameterOverviewName = item["ParameterOverviewName"].ToString(),
                                CreateTime = item["CreateTime"].ToString(),
                            };
                            list.Add(m);
                        }
                    }
                    if (list != null && list.Count() > 0)
                    {
                        return Json(list);
                    }
                }

                return Content("0");
            }
            catch (Exception ex)
            {
                return Content("操作异常：" + ex.Message + "请联系管理员解决");
            }
        }
        #endregion
    }
}
